﻿using M;
using M.Entities;
using Microsoft.Extensions.DependencyInjection;

namespace MClient.Test
{
    internal class Adder
    {
        private static Adder Instance = new Adder();

        public static void Run()
        {
            Instance.AddOneToOne();
            // Instance.AddUser();
           // Instance.AddAudit();
        }

        public void AddOneToOne()
        {
            var dataList = SeedData.GetPlayer();

            var db = DI.InsProvider.GetService<OneToOneContext>();

            db.Player.AddRange(dataList);

            db.SaveChanges();
        }

        public void AddUser()
        {
            var db = DI.InsProvider.GetService<MContext>();
            var tmp = new M.Entities.User()
            {
                Name = "test1",
                Age = 5
            };
            db.User.Add(tmp);
            var insertId=db.SaveChanges();
            Console.WriteLine(insertId);
            // 插入成功后，EfCore默认会将生成Id，返填到模型中。
            Console.WriteLine("刚插入数据的Id:"+tmp.Id);
        }

        public void AddAudit()
        {
            var db = DI.InsProvider.GetService<FilterContext>();
            var tmp = new M.Entities.XFilter()
            {
                Name = "test5",
                TenantId=12
            };
            //db.Set<XFilter>().Attach(tmp);
            db.Set<XFilter>().Add(tmp);
            var insertId = db.SaveChanges();
            Console.WriteLine(insertId);
            // 插入成功后，EfCore默认会将生成Id，返填到模型中。
            Console.WriteLine("刚插入数据的Id:" + tmp.Id);
        }
    }
}